// pages/hotel/hotelDetail/book/payOption/payOption.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    price: 319,
    time: 30 * 60 * 1000,
    isWechatChecked: false,
    isAlipayChecked: false,
    userId: 0,
    hotelId: 0,
    money: 0,
    roomId: 0,
    roomCount: 0,
    startTime: '',
    endTime: '',
    arrivalTime: '',
    year:'',
  },
  onConfirmPayTap() {
    var _this = this;
    wx.showModal({
      title: '',
      content: '是否确认支付',
      success(res) {
        if (res.confirm) {
          _this.insertHotelOrder()
          // console.log('用户点击确定')
        } else if (res.cancel) {
          // console.log('用户点击取消')
        }
      }
    })
  },
  onRadioChange(e) {
    const {
      value
    } = e.target.dataset;
    if (value === 'wechat') {
      this.setData({
        isWechatChecked: true,
        isAlipayChecked: false
      });
    } else if (value === 'alipay') {
      this.setData({
        isAlipayChecked: true,
        isWechatChecked: false
      });
    }
  },
  getUserId() {
    var loginfo = getApp().globalData.loginfo;
    console.log(loginfo)
    this.setData({
      userId: loginfo.userId
    })
  },
  insertHotelOrder() {
    wx.request({
      url: 'http://localhost:8080/hotel/hotelOrder',
      method: 'post',
      header: {
        Authorization: getApp().globalData.authorization
      },
      data: {
        userId: this.data.userId,
        hotelId: this.data.hotelId,
        money: this.data.money,
        roomId: this.data.roomId,
        roomCount: this.data.roomCount,
        orderTime: '',
        startTime: this.data.year+'-'+this.data.startTime,
        endTime: this.data.year+'-'+this.data.endTime,
        arrivalTime: this.data.year+'-'+this.data.arrivalTime,
      },
      success: (resp) => {
        console.log("in", resp.data.rows)
        // this.setData({
        //   couponsList: resp.data.rows
        // })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const now = new Date();
    const year = now.getFullYear();
    console.log(options)
    this.setData({
      hotelId: options.hotelId,
      money: parseInt(options.money),
      roomId: options.roomId,
      roomCount: options.roomCount,
      startTime: options.startTime,
      endTime: options.endTime,
      arrivalTime: options.arrivalTime,
      year: year
    })
    this.getUserId()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})